//
//  ChangePersonSignViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/14.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "ChangePersonSignViewController.h"
#import "UITextView+YLTextView.h"
#import "AFNetworking.h"//主要用于网络请求方法
#import "UIKit+AFNetworking.h"//里面有异步加载图片的方法
#import "AFHTTPSessionManager.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "NavView.h"
#import "ZYButton.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750
@interface ChangePersonSignViewController ()
@property (nonatomic,retain)UITextView *textView;
@end

@implementation ChangePersonSignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.titleView = [ViewFactory makeNavigationTitle:@"修改个性签名"];
    
    UIBarButtonItem *backBtn = [ViewFactory makeNavigationBackWhite:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = backBtn;
    UIButton *buttonNotice = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonNotice.frame = CGRectMake(0, 0, 40, 20);
    buttonNotice.titleLabel.font = [UIFont systemFontOfSize:15];
    [buttonNotice setTitle:@"确定" forState:UIControlStateNormal];
    UIBarButtonItem *btnNoticeItem = [[UIBarButtonItem alloc]initWithCustomView:buttonNotice];
    [buttonNotice addTarget:self action:@selector(changeClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = btnNoticeItem;
    
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-0)];
    backgroundView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0f];
    [self.view addSubview:backgroundView];

    _textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 278*kScale)];
    _textView.font = [UIFont systemFontOfSize:15];
    if (_user.personSign) {
        _textView.text = _user.personSign;
//        _textView.boolhidden = YES;
        _textView.placeholder = @"";
    }
    else
    {
        _textView.placeholder = @"描述下自己呗～";
    }
    
   
    
    _textView.limitLength = [NSNumber numberWithFloat:50];
    [self.view addSubview:_textView];
    

    self.view.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
}
- (void)backClick
{
  [self.navigationController popViewControllerAnimated:YES];
}

- (void)changeClick
{
    if (_textView.text.length!=0)
    {
        [self request];
    }
    else
    {
        [ViewFactory showInfoMsg:@"请输入内容"];
    }
}

- (void)request
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@/userCenter/modifyUserSignature?user_signature=%@",APIYIGOU,_textView.text]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    DYBaseRequest *request = [DYBaseRequest new];
    request.requestUrl = urlStr;
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        NSLog(@"111%@",allDic);
        [self.navigationController popViewControllerAnimated:YES];
        [ViewFactory showSuccess:@"修改成功"];
    } error:^(YTKBaseRequest *request) {
        [ViewFactory showInfoMsg:@"修改失败"];
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
